package com.ling.team.service;

import com.ling.team.domain.*;

import static com.ling.team.service.Date.*;

public class NameListService {
    private Employee[] employees;

    public NameListService() {

        employees = new Employee[12];

        for (int i = 0; i < employees.length; i++) {
            int type = Integer.parseInt(EMPLOYEES[i][0]);

            int id = Integer.parseInt(EMPLOYEES[i][1]);
            String name = EMPLOYEES[i][2];
            int age = Integer.parseInt(EMPLOYEES[i][3]);
            double salary = Integer.parseInt(EMPLOYEES[i][4]);

            switch (type) {
                case EMPLOYEE:
                    employees[i] = new Employee(id, name, age, salary);
                    break;

                case PROGRAMMER:
                    employees[i] = new Programmer(id, name, age, salary, getEquipment(i));
                    break;

                case DESIGNER:
                    double bonus = Double.parseDouble(EMPLOYEES[i][5]);
                    employees[i] = new Designer(id, name, age, salary, getEquipment(i), bonus);
                    break;

                case ARCHITECT:
                    Equipment equipment3 = getEquipment(i);
                    double bonus2 = Double.parseDouble(EMPLOYEES[i][5]);
                    int stock = Integer.parseInt(EMPLOYEES[i][6]);
                    employees[i] = new Architect(id, name, age, salary, equipment3, bonus2, stock);
                    break;
            }

        }
    }

    public Employee[] getAllEmployees() {
        return employees;
    }

    public Employee getEmployee(int id) {
        for (int i = 0; i < employees.length; i++) {
            if (employees[i].getId() == id) {
                return employees[i];
            }
        }
        return null;
    }


    private Equipment getEquipment(int i) {
        int equipType = Integer.parseInt(EQUIPMENTS[i][0]);
        String model = EQUIPMENTS[i][1];
        Equipment equipment = null;
        switch (equipType) {
            case PC:
                equipment = new PC(model, EQUIPMENTS[i][2]);
                break;
            case NOTEBOOK:
                equipment = new NoteBook(model, Double.parseDouble(EQUIPMENTS[i][2]));
                break;
            case PRINTER:
                equipment = new Printer(model, EQUIPMENTS[i][2]);
                break;
            default:
                break;
        }
        return equipment;
    }

    public static void main(String[] args) {
        NameListService nameListService = new NameListService();
        Employee[] allEmployees = nameListService.getAllEmployees();
        for (int i = 0; i < allEmployees.length; i++) {
            System.out.println(allEmployees[i]);
        }
    }

    public Employee[] getEmployees() {
        return employees;
    }
}



